(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery'), require('./template.html')) :
    typeof define === 'function' && define.amd ? define(['jquery', 'text!./template.html'], factory) :
    global.modal = factory($, '<div><div class="modal"></div></div>');
}(this, function ($, template) { 'use strict';

  var Modal = function Modal(elem, options) {
    options = options || {};
    this.$elem = options.template ? $(options.template) : $(template);
    this.$elem.find('.modal').append(elem);

    var self = this;

    this.$elem.find('.close').bind('click', function() {
      self.destroy();
      return false;
    });
    $('body').append(this.$elem);
  }

  Modal.prototype.show = function() {
    this.$elem.show();
  }

  Modal.prototype.hide = function() {
    this.$elem.hide();
  }

  Modal.prototype.destroy = function() {
    this.$elem.remove();
  }

  return function(elem, options) {
    return new Modal(elem, options);
  }

}))